{% extends "_base.html" %}

{% block main %}

<script>
    $(function () {
        $('#signinForm').submit(function (e) {
            e.preventDefault();
            var data = {
                accountName: $('#accountName').val(),
                password: $('#password').val()
            };
            $.ajax({
                type: 'post',
                url: '/signin',
                data: JSON.stringify(data),
                success: function (resp) {
                    if (resp.error) {
                        $('#error').text(resp.error);
                    } else {
                        location.assign('/signout');
                    }
                },
                contentType: 'application/json',
                dataType: 'json'
            });
        });
    });
</script>

<a style="color: red">已登出</a>
<form id="signinForm">
    <div class="form-group">
        <p id="error" class="text-danger"></p>
    </div>
    <div class="form-group">
        <label>Email</label>
        <input id="accountName" type="email" class="form-control" placeholder="Email">
    </div>
    <div class="form-group">
        <label>Password</label>
        <input id="password" type="password" class="form-control" placeholder="Password">
    </div>
    <button type="submit" class="btn btn-outline-primary">Submit</button>
</form>

{% endblock %}
